
require(['./config'],()=>{
    require(['template','swiper','header','footer'],(template,Swiper)=>{
        new Swiper ('.swiper-container', {
            loop: true, // 循环模式选项
            autoplay:true,
            // 如果需要分页器
            pagination: {
              el: '.swiper-pagination',
            },
            
            // 如果需要前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev',
            },
            
            // 如果需要滚动条
            scrollbar: {
              el: '.swiper-scrollbar',
            },


          })

        class Index {
            constructor(){
                this.getJson().then(()=>{
                    this.renderJson()
                })
                this.getRap2().then(()=>{
                    this.renderRap2()
                })
            }
            getJson(){
                return new Promise (resolve=>{
                    $.get('/libs/json/homeCategory.json',resp=>{
                        this.respJson = [
                            ...resp
                        ]
                        resolve()
                    })
                })
                
            }

            getRap2(){
                return new Promise(resolve=>{
                    $.get('http://rap2api.taobao.org/app/mock/239068/index',resp=>{
                        this.respRap2 = resp.body
                        resolve()
                    })
                })
                
            }

            renderJson(){
                let popular = template('template1',{ list:this.respJson })
                $('#box1').html(popular)
            }

            renderRap2(){
                let box2 = template('tep-box2',{ list:this.respRap2.new })
                $('#box2').html(box2)

                let shop = template('tep-new',{ shop:this.respRap2.shop })
                $('#new-shop').html(shop)

                let item1 = template('tep-item1',{ list:this.respRap2.item1 })
                $('#item1').html(item1)

                let item2 = template('tep-item2',{ list:this.respRap2.item2 })
                $('#item2').html(item2)

                let shop1 = template('tep-new1',{ shop:this.respRap2.shop })
                $('#new-shop1').html(shop1)
            }
           
        }
        new Index()

        
    })

})